//
//  NormalController.m
//  OCDemo
//
//  Created by BH on 15/10/10.
//  Copyright © 2015年 baohan. All rights reserved.
//

#import "NormalController.h"

@interface NormalController ()

@end

@implementation NormalController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - 重写父类方法
-(Class)labelClass
{
    return [MLLabel class];
}

-(NSInteger)resultCount
{
    return 5;
}

-(void)changeToResult:(NSInteger)result
{
    self.label.textAlignment = NSTextAlignmentCenter;
    self.label.textColor = [UIColor redColor];
    self.label.font = [UIFont systemFontOfSize:14.f];
    self.label.numberOfLines = 1;
    self.label.textInsets = UIEdgeInsetsZero;
    self.label.adjustsFontSizeToFitWidth = YES;
    self.label.text = @"人生若只如初见，何事秋风悲画扇。等闲变却故人心，却道故人心易变。骊山语罢清宵半，泪雨零铃终不怨。\n何如薄幸锦衣郎，比翼连枝当日愿。";
    [self.label setDoBeforeDrawingTextBlock:nil];
    
    if (result == 0) {
        
    }
    else if (result == 1)
    {
        self.label.textInsets = UIEdgeInsetsMake(5, 5, 5, 5);
        self.label.textColor = [UIColor blackColor];
        self.label.font = [UIFont systemFontOfSize:16.f];
        self.label.numberOfLines = 2;
    }
    else if (result == 2)
    {
        self.label.textInsets = UIEdgeInsetsMake(20, 5, 5, 5);
        self.label.textColor = [UIColor blueColor];
        self.label.numberOfLines = 0;
        self.label.textAlignment = NSTextAlignmentLeft;
        self.label.adjustsFontSizeToFitWidth = NO;
    }
    else if (result == 3)
    {
        //测试绘制回调
        self.label.numberOfLines = 0;
        self.label.textAlignment = NSTextAlignmentLeft;
        self.label.textInsets = UIEdgeInsetsMake(0, 10, 0, 5);
        [self.label setDoBeforeDrawingTextBlock:^(CGRect rect, CGPoint beginOffset, CGSize drawSize) {
            
            CGContextRef ctx = UIGraphicsGetCurrentContext();
            if (!ctx) {
                return;
            }
            
            [[UIColor darkGrayColor] setFill];
            
            CGContextFillRect(ctx, CGRectMake(beginOffset.x - 10.0f, beginOffset.y, 5.0f, drawSize.height));
        }];
    }
    else if (result == 4)
    {
        //测试下attrStr
        self.label.numberOfLines = 0;
        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"人生若只如初见，何事秋风悲画扇。等闲变却故人心，却道故人心易变。骊山语罢清宵半，泪雨零铃终不怨。\n何如薄幸锦衣郎，比翼连枝当日愿。" ];
        [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(2, 10)];
        self.label.attributedText = attrStr;
    }
    
    if (result != 0) {
        self.label.frameWidth = self.view.frameWidth -10.f*2;
        [self.label sizeToFit];
    }
}

@end
